package com.tyrant.houtai;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.sunshine.retrofit.HttpUtil;
import com.sunshine.retrofit.interfaces.ErrorFunListener;
import com.sunshine.retrofit.interfaces.Success;
import com.tyrant.houtai.adapter.StatisticalAdapter;
import com.tyrant.houtai.bean.StatisticalBean;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

public class StatisticalActivity extends AppCompatActivity {


    @Bind(R.id.rv_list)
    RecyclerView rv_list;
    private StatisticalAdapter contactsAdapter;
    private ArrayList<StatisticalBean.ResultBean> contactBeanArrayList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_statistical);
        ButterKnife.bind(this);
        initRecycler();
        saveInfo();
    }

    private void saveInfo() {
        new HttpUtil.Builder("users/getStatisticsCount")
                .Tag(this)//需要取消请求的tag
                .Success(new Success() {
                    @Override
                    public void Success(String model) {
                        StatisticalBean contactUsBean = new Gson().fromJson(model, StatisticalBean.class);
                        if (contactUsBean.getFlag() == 1) {
                            contactsAdapter.setNewData(contactUsBean.getResult());
                        } else {
                            Toast.makeText(StatisticalActivity.this, contactUsBean.getMsg(), Toast.LENGTH_SHORT).show();
                        }
                    }
                }).ErrorEventFunc(new ErrorFunListener() {
            @Override
            public void ErrorFun(Object... values) {
                String value = (String) values[1];
            }
        })
                .get();
    }

    private void initRecycler() {
        rv_list.setLayoutManager(new LinearLayoutManager(this));
        contactsAdapter = new StatisticalAdapter(R.layout.sms_item, contactBeanArrayList);
        //todo 添加数据
        rv_list.setAdapter(contactsAdapter);


    }
}
